package com.ifast.asset.controller;


import java.util.Arrays;

import com.ifast.asset.domain.Assets;
import com.ifast.asset.domain.TaskipDO;
import com.ifast.asset.service.AssetsService;
import com.ifast.asset.service.TaskipService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.annotation.Log;
import com.ifast.common.base.BaseController;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-02-26 15:03:03 | Aron</small>
 */
@Controller
@RequestMapping("/wxmp/taskip")
public class TaskipController extends BaseController {
	@Autowired
	private TaskipService taskipService;
	@Autowired
	private AssetsService assetsService;
	
	@GetMapping()
	@RequiresPermissions("wxmp:taskip:taskip")
	String Taskip(){
	    return "wxmp/taskip/taskip";
	}
	
	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("wxmp:taskip:taskip")
	public Result<Page<TaskipDO>> list(TaskipDO taskipDTO,int pageNum,int pageSize){
        Wrapper<TaskipDO> wrapper = new EntityWrapper<>(taskipDTO).orderBy("id", false);
        Page<TaskipDO> page = taskipService.selectPage(getPage(TaskipDO.class,pageNum,pageSize), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wxmp:taskip:add")
	String add(){
	    return "wxmp/taskip/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wxmp:taskip:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		TaskipDO taskip = taskipService.selectById(id);
		model.addAttribute("taskip", taskip);
	    return "wxmp/taskip/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wxmp:taskip:add")
	public Result<String> save( TaskipDO taskip){
		taskipService.insert(taskip);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wxmp:taskip:edit")
	public Result<String>  update( TaskipDO taskip){
		boolean update = taskipService.updateById(taskip);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wxmp:taskip:remove")
	public Result<String>  remove( Integer id){
		taskipService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wxmp:taskip:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		taskipService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

}
